﻿using DxfMonitor.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DxfMonitor
{
    public class DxfComparer
    {
        private string currentDir;
        private string lastDir;

        public DxfComparer(string lastDir, string currentDir)
        {
            this.lastDir = lastDir;
            this.currentDir = currentDir;
        }



        public void Compare2DxfHistoryStatuses(IList<DxfHistoryStatus> last, IList<DxfHistoryStatus> current, out IList<DxfHistoryStatus> added, out IList<DxfHistoryStatus> removed)
        {
            HashSet<DxfHistoryStatus> setCurrent = new HashSet<DxfHistoryStatus>(current);
            HashSet<DxfHistoryStatus> setLast = new HashSet<DxfHistoryStatus>(last);
            added = setCurrent.Except(setLast).ToList();
            removed = setLast.Except(setCurrent).ToList();
        }

        public IList<DxfHistoryStatus> ScanDxfInfos()
        {
            return ScanDxfInfosOfFolder(currentDir);
            //#if DEBUG
            //            string[] currentFiles = Directory.GetFiles(currentDir, "*.*", SearchOption.TopDirectoryOnly);

            //#else
            //            string[] currentFiles = Directory.GetFiles(currentDir, "*.dxf", SearchOption.AllDirectories);

            //#endif
            //            return currentFiles.Select(x => new DxfHistoryStatus(currentDir, x)).ToList();
        }


        public static IList<DxfHistoryStatus> ScanDxfInfosOfFolder(string folder)
        {
            SearchOption searchOption = File.Exists(Path.Combine(folder, "只比较顶层.txt")) ?
                SearchOption.TopDirectoryOnly : SearchOption.AllDirectories;
#if DEBUG
            string[] currentFiles = Directory.GetFiles(folder, "*.*", searchOption);
#else
            string[] currentFiles = Directory.GetFiles(folder, "*.dxf", searchOption);
#endif

            return currentFiles.Select(x => new DxfHistoryStatus(folder, x)).ToList();
        }

    }
}
